package com.sfgeeq.quartz;

import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/8/7.
 */
public class HelloJob  implements Job{
    //jobDataMap 这个
    //在继承了job 接口后，需要重写execute
    public void execute(JobExecutionContext context) throws JobExecutionException {
        SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前的系统时间为："+sf.format(new Date()));

        JobKey key=context.getJobDetail().getKey();
        System.out.println("当前任务的名称：job.name:"+key.getName());
        System.out.println("当前任务的组别：job.group:"+key.getGroup());

        TriggerKey triggerKey=context.getTrigger().getKey();
        System.out.println("当前任务的名称：trigger.name:"+triggerKey.getName());
        System.out.println("当前任务的组别：trigger.group:"+triggerKey.getGroup());
        //获取JJobDataMap方法一
        JobDataMap jobDataMap=context.getJobDetail().getJobDataMap();
        JobDataMap triggerDateMap=context.getTrigger().getJobDataMap();
        String message=jobDataMap.getString("message");// ?= 定时任务名称
        String triggerMessage=triggerDateMap.getString("triggerMessage");//?=Trigger名称
        System.out.println("JOB_message："+message);
        System.out.println("trigger_message："+triggerMessage);
        //获取JJobDataMap方法二 合并 job 和 trigger的值，如果key相同，就取trigger中的值
        JobDataMap jobDataMapMerged=context.getMergedJobDataMap();
        System.out.println("Merged_JOB_message："+jobDataMapMerged.getString("message"));
        System.out.println("Merged_JOB_message："+jobDataMapMerged.getString("triggerMessage"));


        System.out.println("--------------------------");
    }
}
